/**
 * @author  Thomas Lehmann
 * @file    FactoryTest.js
 * @note    //http://docs.busterjs.org/en/latest/modules/buster-assertions/
 *
 * Copyright (c) 2013 Thomas Lehmann
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
var buster     = require("buster");
var ClassTools = require("../src/ClassTools.js")
var Class      = ClassTools.Class;
var Factory    = ClassTools.Factory;

/**
    Test class using the "Class" mechanism.
 */
var Test1 = ClassTools.Class({
    initialize : function() { this.name = "Test1"; }
});

var Test2 = ClassTools.Class({
    initialize : function() { this.name = "Test2"; }
});

/**
    Testing class (function) "Class".
 */
buster.testCase("Testing 'Factory' class:", {
    /**
        Creating an instance with 'new' and checking
        the intial state.
     */
    "testing initial states": function() {
        var factory = new Factory();
        assert.equals(0, factory.size());
    },

    "testing 'Factory.register(...)'": function() {
        var factory = new Factory();
        assert.equals(true,  factory.register(1, Test1));
        assert.equals(false, factory.register(1, Test1));
        assert.equals(true,  factory.register(2, Test2));
        assert.equals(false, factory.register(2, Test2));
    },

    "testing 'Factory.createInstance(...)'": function() {
        var factory = new Factory();
        factory.register(1, Test1);
        factory.register(2, Test2);

        var instance1 = factory.createInstance(1);
        refute.equals(instance1, undefined);
        assert.equals("Test1", instance1.name);

        var instance2 = factory.createInstance(2);
        refute.equals(instance2, undefined);
        assert.equals("Test2", instance2.name);
    }
});


